<style>
    body {
        background-color: #FAF8F8 !important;
    }

    .file_manager {
        padding-top: 10px;
    }

    .was-validated .custom-select:invalid+.select2 .select2-selection {
        border-color: #fd3995 !important;
        padding-right: calc(1.47em + 1rem);
        background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' fill='%23fd3995' viewBox='-2 -2 7 7'><path stroke='%23fd3995' d='M0 0l3 3m0-3L0 3'/><circle r='.5'/><circle cx='3' r='.5'/><circle cy='3' r='.5'/><circle cx='3' cy='3' r='.5'/></svg>");
        background-repeat: no-repeat;
        background-position: center right calc(.3675em + .25rem);
        background-size: calc(.735em + .5rem) calc(.735em + .5rem);
    }

    .was-validated .custom-select:valid+.select2 .select2-selection {
        border-color: #1dc9b7 !important;
        padding-right: calc(1.47em + 1rem);
        background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'><path fill='%231dc9b7' d='M2.3 6.73L.6 4.53c-.4-1.04.46-1.4 1.1-.8l1.1 1.4 3.4-3.8c.6-.63 1.6-.27 1.2.7l-4 4.6c-.43.5-.8.4-1.1.1z'/></svg>");
        background-repeat: no-repeat;
        background-position: center right calc(.3675em + .25rem);
        background-size: calc(.735em + .5rem) calc(.735em + .5rem);
    }

    .was-validated .uim-file:invalid+button {
        border-color: #fd3995 !important;
        padding-right: calc(1.47em + 1rem);
        background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' fill='%23fd3995' viewBox='-2 -2 7 7'><path stroke='%23fd3995' d='M0 0l3 3m0-3L0 3'/><circle r='.5'/><circle cx='3' r='.5'/><circle cy='3' r='.5'/><circle cx='3' cy='3' r='.5'/></svg>");
        background-repeat: no-repeat;
        background-position: center right calc(.3675em + .25rem);
        background-size: calc(.735em + .5rem) calc(.735em + .5rem);
    }

    .was-validated .uim-file:valid+button {
        border-color: #1dc9b7 !important;
        padding-right: calc(1.47em + 1rem);
        background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'><path fill='%231dc9b7' d='M2.3 6.73L.6 4.53c-.4-1.04.46-1.4 1.1-.8l1.1 1.4 3.4-3.8c.6-.63 1.6-.27 1.2.7l-4 4.6c-.43.5-.8.4-1.1.1z'/></svg>");
        background-repeat: no-repeat;
        background-position: center right calc(.3675em + .25rem);
        background-size: calc(.735em + .5rem) calc(.735em + .5rem);
    }

    table.dataTable tbody td.select-checkbox::before,
    table.dataTable tbody th.select-checkbox::before {
        margin-top: auto;
    }

    table.dataTable tr.selected td.select-checkbox:after,
    table.dataTable tr.selected th.select-checkbox:after {
        margin-top: -5px;
    }
</style>
<script>
    var listEnumSelect = function (tag_name, enum_obj, filter) {
        var filters = (filter || '').split(',');
        var arr = [];
        for (var i in enum_obj) {
            if (filters.includes(i)) {
                continue;
            }
            if (isFinite(i)) {
                switch (tag_name) {
                    case 'SELECT':
                        arr.push('<option value="' + i + '">' + enum_obj[i] + '</option>');
                        break;
                    case 'DATALIST':
                        arr.push('<option value="' + enum_obj[i] + '" />');
                        break;
                }
            } else {
                continue;
            }
        }
        return arr.join('');
    };
    var init_enum_select = function () {
        $('[uim-enum]:not([uim-render])').attr('uim-render', true).each(function () {
            var obj_value = $(this).attr('uim-value') || '';
            $(this)
                .append(listEnumSelect(this.tagName, eval('uim.enum.' + $(this).attr('uim-enum')), $(this).attr('uim-filter-value')))
                .val(obj_value.split(',')).trigger('uim-render');
        });
    };
    // 将select元素自动加载接口数据；todo: table也可以这样做，另指定一行模板，但需要考虑接口传入参数合理性
    var init_api_select = function () {
        $('select[uim-api]:not([uim-render])').attr('uim-render', true).each(function () {
            var select_obj = this;
            var api_info = $(select_obj).attr('uim-api').split(',');
            var api_data = $(select_obj).attr('uim-api-data') ? eval('(' + $(select_obj).attr('uim-api-data') + ')') : {};
            var api_attr = $(select_obj).attr('uim-api-attr');
            api_attr = api_attr ? api_attr.split(',') : [];
            uim.api.emit({
                code: api_info[0],
                data: api_data,
                success: function (data) {
                    var data_list = [];
                    $(data[api_info[1]]).each(function () {
                        var tmp_option = $('<select><option></option></select>');
                        tmp_option.find('option').attr('value', this[api_info[2]]).text(this[api_info[3]])
                        var that = this;
                        $(api_attr).each(function () {
                            tmp_option.find('option').attr('data-' + this, that[this])
                        })
                        data_list.push(tmp_option.html());
                    })
                    var obj_value = $(select_obj).attr('uim-value') || '';
                    $(select_obj).append(data_list.join('')).val(obj_value.split(',')).trigger('uim-render');
                },
                error: function (err) {
                    $(select_obj).append('<option value="">【数据接口请求失败】</option>').trigger('uim-render');
                    return true;
                }
            })
        });
    };
    // 将select元素自动加载数据
    // init_data_select($('.search-form [name=project_id]'), data.project_list, 'project_id', 'project_name', []);
    var init_data_select = function (select_objs, data_list, data_i, data_v, data_ext = []) {
        $(data_list).each(function () {
            var tmp_option = $('<option value="' + this[data_i] + '"' + (data_ext.length ? (' data-' + data_ext.join('="" data-') + '=""') : '') + '>' + this[data_v] + '</option>')
            var that = this;
            $(data_ext).each(function () {
                tmp_option.data(this, that[this]);
            });
            $(select_objs).append(tmp_option);
        })
    };
    var init_auto_render = function () {
        $('[uim-auto-render]').each(function () {
            var dom_obj = this;
            var auto_render = function (data) {
                // todo: template_code / template_selector / template_path
                // todo: include增加属性from，默认为在线模板online，可设置为selector（本地页面使用）
                uim.render({
                    data,
                    template: $(dom_obj).html(),
                    template_type: 0, // 0默认为模板内容字符串（不支持include），1为标签对象（取innerHTML，其中include时从页面dom.getbyId来取），2为在线模板（include从线上获取）；
                    cache: false, // 当template_type=2时有效，将会把在线模板缓存到localStorage
                    context: window, // 当template_type=1时有效，用于在当前上下文中寻找dom
                    done: function (res) {
                        var render_dom = $(res.content);
                        $(dom_obj).after(render_dom);
                        $(dom_obj).trigger('uim-render', [{ render_dom }]).remove();
                    }
                });
            };

            var api_info = $(dom_obj).attr('uim-api');
            if (!api_info) {
                var render_data = $(dom_obj).attr('uim-data') ? eval('(' + $(dom_obj).attr('uim-data') + ')') : {};
                auto_render(render_data);
                return;
            }
            var api_data = $(dom_obj).attr('uim-api-data') ? eval('(' + $(dom_obj).attr('uim-api-data') + ')') : {};
            uim.api.emit({
                code: api_info,
                data: api_data,
                success: auto_render,
                error: function (err) {
                    $('<p>【数据接口请求失败】</p>').replaceAll(dom_obj);
                    return true;
                }
            })
        });
    };
    var loading = function (text) {

        var dialog = bootbox.dialog({
            message: '<p class="text-center mb-0"><i class="fa fa-spin fa-spinner"></i> ' + (text || '加载中') + '...</p>',
            centerVertical: true,
            closeButton: false
        });
        return {
            hide: function () {
                dialog.init(function () {
                    setTimeout(function () {
                        dialog.modal('hide');
                    }, 500);
                });
            }
        }
    };

    (function () {
        'use strict';
        window.addEventListener('load', function () {
            // Fetch all the forms we want to apply custom Bootstrap validation styles to
            var forms = document.getElementsByClassName('needs-validation');
            // Loop over them and prevent submission
            var validation = Array.prototype.filter.call(forms, function (form) {
                form.addEventListener('submit', function (event) {
                    event.preventDefault();
                    event.stopPropagation();
                    form.classList.add('was-validated');
                    form.removeAttribute('check-success');
                    if (form.checkValidity()) {
                        var data = {}, form_obj = new FormData(form);
                        form_obj.forEach(function (v, k, fd) {
                            if (data[k]) {
                                if (!data[k].push) data[k] = [data[k]];
                                data[k].push(v);
                            } else {
                                data[k] = v;
                            }
                        });
                        // form.setAttribute('check-success', true);
                        // form.dispatchEvent(new CustomEvent('uim-submit', { detail: { data: data } }));
                        $(form).attr('check-success', true).trigger('uim-submit', [{ data }]);
                    }
                }, false);
            });
        }, false);
        if ($.fn.datepicker) {
            $.fn.datepicker.dates.cn = {
                days: ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"],
                daysShort: ["周日", "周一", "周二", "周三", "周四", "周五", "周六", "周日"],
                daysMin: ["日", "一", "二", "三", "四", "五", "六", "日"],
                months: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
                monthsShort: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
                today: "今天",
                clear: "清除",
                titleFormat: "MM yyyy",
                monthsTitle: '月份',
                suffix: [],
                meridiem: ["上午", "下午"]
            };
            $.fn.datepicker.defaults.language = 'cn';
        }
    })();
    $.fn.serializeObject = function () {
        var o = {};
        var a = this.serializeArray();
        $.each(a, function () {
            if (o[this.name] !== undefined) {
                if (!o[this.name].push) {
                    o[this.name] = [o[this.name]];
                }
                o[this.name].push(this.value || '');
            } else {
                o[this.name] = this.value || '';
            }
        });
        return o;
    };
    $(function () {
        init_enum_select();
        init_api_select();
        init_auto_render();

        $(document).on('click', 'a,[uim-view]', function (event) {
            var view = $(this).attr('uim-view') || $(this).attr('href');
            if (!view || (this.tagName == 'A' && view.substr(0, 7) != 'view://')) return; // 如果是a标签指向javascript:;则不处理（a不再作为跳转其他url来使用）
            view = view.split(':').pop().split('//').pop();
            event.preventDefault();
            event.stopPropagation();
            var data = $(this).attr('uim-view-data') ? JSON.parse($(this).attr('uim-view-data')) : {};
            var target_window = $(this).attr('uim-target') == 'parent' ? parent : window;
            view && uim.view(view, data, target_window, null, null, $(this).attr('uim-view-hash') !== 'hide');
        });
    });

    var init_uim_file = function (selector) {
        uim.fileManager.init({
            window: window,
            eles: selector || '.uim-file',
            opt: 'select', //'select' or 'show'
            up_callback: function (input_ele, file_url) {
                console.log('上传成功!!!!');
                if (input_ele == '') {
                    //

                } else if (input_ele == '') {
                    //

                }
            },
            change: function (input_ele) {
                var json_data = null;
                try {
                    json_data = JSON.parse($(input_ele).val())
                    $(json_data).each(function () {
                        this.key = this.key || $(input_ele).attr('name');
                        this.uid = this.uid || ('' + Math.random() * 10000000000000).substr(0, 13) * 1;
                    })
                    $(input_ele).val(JSON.stringify(json_data))
                } catch (e) {
                    $(input_ele).val('')
                }
            }
        });
    }
    var datatables_language = {
        lengthMenu: "Display _MENU_ records per page",
        zeroRecords: "未找到记录",
        info: "第 _PAGE_ 页 / 共 _PAGES_ 页,共 _TOTAL_ 条记录",
        infoEmpty: "No records available",
        // infoFiltered: "(filtered from _MAX_ total records)"
        infoFiltered: "",
        sInfo: "第 _PAGE_ 页 / 共 _PAGES_ 页,共 _TOTAL_ 条记录",
        // sInfoEmpty: "No records available",
        sProcessing: '<div class="d-flex align-items-center justify-content-center fs-lg"><div class="spinner-border spinner-border-sm text-primary mr-2" role="status"><span class="sr-only"> 加载中...</span></div> 处理中...</div>',
        sSearch: '<div class="input-group-text d-inline-flex width-3 align-items-center justify-content-center border-bottom-right-radius-0 border-top-right-radius-0 border-right-0"><i class="fal fa-search"></i></div>',
        sSearchPlaceholder: '搜索',
        searchPlaceholder: "搜索",

        // "sProcessing": "处理中...",
        "sLengthMenu": "显示 _MENU_ 项结果",
        "sZeroRecords": "没有匹配结果",
        // "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
        "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
        // "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
        "sInfoPostFix": "",
        // "sSearch": "搜索：",
        "sUrl": "",
        "sEmptyTable": "表中数据为空",
        "sLoadingRecords": "载入中...",
        "sInfoThousands": ",",
        "oPaginate": {
            "sFirst": "首页",
            "sPrevious": "上页",
            "sNext": "下页",
            "sLast": "末页"
        },
        "oAria": {
            "sSortAscending": ": 以升序排列此列",
            "sSortDescending": ": 以降序排列此列"
        },
        'select': {
            rows: ''
        },
    };
    if (localStorage.main_view == 'main2')
        $(window).resize(function () {
            if (!window.ignore_resize)
                parent.updateIframeHeight(view_name);
        });
</script>

<!-- <link rel="stylesheet" href="/uim_file_manager.css">
<link rel="stylesheet" href="/font-awesome/4.4.0/css/font-awesome.css"> -->